package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_ZYJCJLData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_ZYJCJL;

public class InsertEMR_ZYJCJLDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_ZYJCJLDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_ZYJCJL> list = new ArrayList<EMR_ZYJCJL>();
		list = GetEMR_ZYJCJLData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_ZYJCJL temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_ZYJCJL where ZYH='"+
					temp.getZYH()
					+"' and YLJGZZJGDM = '"+temp.getYLJGZZJGDM()+"'"
			
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_ZYJCJL ("
					+ "ZYH,"
					+ "YLJGZZJGDM,"
					+ "YLJGMC,"
					+ "JCXMLSH,"
					+ "HZZSYH,"
					+ "JCBGDBH,"
					+ "DZSQDBH,"
					+ "XM,"
					+ "XB,"
					+ "NL,"
					+ "LXRDHHM,"
					+ "KSDM,"
					+ "KSMC,"
					+ "BQMC,"
					+ "BFH,"
					+ "BCH,"
					+ "JCBGDMC,"
					+ "JCXMDM,"
					+ "JCXMMC,"
					+ "JCLBDM,"
					+ "JCLBMC,"
					+ "JCJGYCBZ,"
					+ "JCJG,"
					+ "CKZ,"
					+ "JCJLDW,"
					+ "JCBW,"
					+ "JCFF,"
					+ "JCGCMS,"
					+ "JCSJ,"
					+ "JCJL,"
					+ "JBZDDM,"
					+ "JBZDMC,"
					+ "BSZY,"
					+ "TZ,"
					+ "JCMD,"
					+ "SQRGH,"
					+ "SQRXM,"
					+ "SQKSDM,"
					+ "SQKS,"
					+ "SQJGDM,"
					+ "SQJGMC,"
					+ "JCRQ,"
					+ "JCRYGH,"
					+ "JCRYXM,"
					+ "FHRGH,"
					+ "FHRXM,"
					+ "JCKSDM,"
					+ "JCKS,"
					+ "JCJGDM,"
					+ "JCJGMC,"
					+ "JZJGDM,"
					+ "BCRQ,"
					+ "ZRLSH,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					
					
					
					+ "'" + checkStr(temp.getZYH()) + "'," 
					+ "'" + checkStr(temp.getYLJGZZJGDM()) + "'," 
					+ "'" + checkStr(temp.getYLJGMC()) + "'," 
					+ "" + checkStr(temp.getJCXMLSH()) + "," 
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getJCBGDBH()) + "'," 
					+ "'" + checkStr(temp.getDZSQDBH()) + "',"
					+ "'" + checkStr(temp.getXM()) + "',"
					+ "'" + checkStr(temp.getXB()) + "'," 
					+ "'" + checkStr(temp.getNL()) + "'," 

					+ "'" + checkStr(temp.getLXRDHHM()) + "'," 
					+ "'" + checkStr(temp.getKSDM()) + "'," 
					+ "'" + checkStr(temp.getKSMC()) + "'," 
					+ "'" + checkStr(temp.getBQMC()) + "'," 
					+ "'" + checkStr(temp.getBFH()) + "',"
					+ "'" + checkStr(temp.getBCH()) + "',"
					+ "'" + checkStr(temp.getJCBGDMC()) + "'," 
					+ "'" + checkStr(temp.getJCXMDM()) + "'," 
					+ "'" + checkStr(temp.getJCXMMC()) + "'," 
					+ "'" + checkStr(temp.getJCLBDM()) + "'," 
					+ "'" + checkStr(temp.getJCLBMC()) + "'," 
					+ "'" + checkStr(temp.getJCJGYCBZ()) + "'," 
					+ "'" + checkStr(temp.getJCJG()) + "'," 
					+ "'" + checkStr(temp.getCKZ()) + "'," 
					+ "'" + checkStr(temp.getJCJLDW()) + "'," 
					+ "'" + checkStr(temp.getJCBW()) + "'," 
					
					+ "'" + checkStr(temp.getJCFF()) + "'," 
					+ "'" + checkStr(temp.getJCGCMS()) + "',"
					+ "'" + checkStr(temp.getJCSJ()) + "'," 
					+ "'" + checkStr(temp.getJCJL()) + "'," 
					+ "'" + checkStr(temp.getJBZDDM()) + "'," 
					+ "'" + checkStr(temp.getJBZDMC()) + "'," 
					+ "'" + checkStr(temp.getBSZY()) + "'," 
					+ "'" + checkStr(temp.getTZ()) + "'," 
					+ "'" + checkStr(temp.getJCMD()) + "'," 
					+ "'" + checkStr(temp.getSQRGH()) + "',"
					+ "'" + checkStr(temp.getSQRXM()) + "'," 
					+ "'" + checkStr(temp.getSQKSDM()) + "'," 
					+ "'" + checkStr(temp.getSQKS()) + "'," 
					+ "'" + checkStr(temp.getSQJGDM()) + "'," 
					+ "'" + checkStr(temp.getSQJGMC()) + "'," 
					
					
					+ "'" + checkStr(temp.getJCRQ()) + "'," 
					+ "'" + checkStr(temp.getJCRYGH()) + "',"
					+ "'" + checkStr(temp.getJCRYXM()) + "'," 
					+ "'" + checkStr(temp.getFHRGH()) + "'," 
					+ "'" + checkStr(temp.getFHRXM()) + "'," 
					+ "'" + checkStr(temp.getJCKSDM()) + "'," 
					+ "'" + checkStr(temp.getJCKS()) + "'," 
					+ "'" + checkStr(temp.getJCJGDM()) + "'," 
					+ "'" + checkStr(temp.getJCJGMC()) + "'," 
					+ "'" + checkStr(temp.getJZJGDM()) + "',"

					
					
					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getZRLSH()) + "'," 
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
